package org.szgb.console.ht.electricity.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import org.szgb.console.utils.PageDto;
import org.szgb.core.base.entity.BeanEntity;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
public class HtElectricitySettlementBillItemModel extends BeanEntity<HtElectricitySettlementBillItemModel> {
    @Serial
    private static final long serialVersionUID = 1L;
    private HtElectricitySettlementBillModel htElectricitySettlementBillModel;
    private String connectionType;
    private String connectionLocation;
    private String computationRule;
    private Integer sortOrder;

    public HtElectricitySettlementBillItemModel() {
    }

    public HtElectricitySettlementBillItemModel(String id) {
        this.setId(id);
    }

    public HtElectricitySettlementBillItemModel(HtElectricitySettlementBillItemModel.HtElectricitySettlementBillItemModelFindDto htElectricitySettlementBillItemModelFindDto) {
        this.setId(htElectricitySettlementBillItemModelFindDto.getId());
        this.setHtElectricitySettlementBillModel(new HtElectricitySettlementBillModel(htElectricitySettlementBillItemModelFindDto.getBillModelId()));
        this.setPageDto(htElectricitySettlementBillItemModelFindDto.getPageDto());
    }

    public HtElectricitySettlementBillItemModel(HtElectricitySettlementBillItemModel.HtElectricitySettlementBillItemModelSaveDto htElectricitySettlementBillItemModelSaveDto) {
        this.setId(htElectricitySettlementBillItemModelSaveDto.id);
        this.setHtElectricitySettlementBillModel(new HtElectricitySettlementBillModel(htElectricitySettlementBillItemModelSaveDto.billModelId));
        this.setConnectionType(htElectricitySettlementBillItemModelSaveDto.connectionType);
        this.setConnectionLocation(htElectricitySettlementBillItemModelSaveDto.connectionLocation);
        this.setComputationRule(htElectricitySettlementBillItemModelSaveDto.computationRule);
        this.setSortOrder(htElectricitySettlementBillItemModelSaveDto.sortOrder);
    }

    public HtElectricitySettlementBillItemModel.HtElectricitySettlementBillItemModelView toHtElectricitySettlementBillItemModelView() {
        return new HtElectricitySettlementBillItemModel.HtElectricitySettlementBillItemModelView(this);
    }

    @Data
    @Schema(title = "电量结算单细项模板信息", description = "电量结算单细项模板信息")
    public static class HtElectricitySettlementBillItemModelView {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "表模板id")
        private String billModelId;
        @Schema(description = "表模板名称")
        private String billModelName;
        @Schema(description = "接用类型")
        private String connectionType;
        @Schema(description = "接用地点")
        private String connectionLocation;
        @Schema(description = "计算规则")
        private String computationRule;
        @Schema(description = "排序参数")
        private Integer sortOrder;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "创建时间")
        private LocalDateTime createdAt;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "更新时间")
        private LocalDateTime updatedAt;
        @Schema(description = "创建人id")
        private String createdById;
        @Schema(description = "创建人姓名")
        private String createdByName;
        @Schema(description = "更新人id")
        private String updatedById;
        @Schema(description = "更新人姓名")
        private String updatedByName;

        public HtElectricitySettlementBillItemModelView(HtElectricitySettlementBillItemModel htElectricitySettlementBillItemModel) {
            this.id = htElectricitySettlementBillItemModel.getId();
            this.billModelId = htElectricitySettlementBillItemModel.getHtElectricitySettlementBillModel().getId();
            this.billModelName = htElectricitySettlementBillItemModel.getHtElectricitySettlementBillModel().getName();
            this.connectionType = htElectricitySettlementBillItemModel.getConnectionType();
            this.connectionLocation = htElectricitySettlementBillItemModel.getConnectionLocation();
            this.computationRule = htElectricitySettlementBillItemModel.getComputationRule();
            this.sortOrder = htElectricitySettlementBillItemModel.getSortOrder();
            this.createdAt = htElectricitySettlementBillItemModel.getCreatedAt();
            this.updatedAt = htElectricitySettlementBillItemModel.getUpdatedAt();
            if (htElectricitySettlementBillItemModel.getCreatedBy() != null) {
                this.createdById = htElectricitySettlementBillItemModel.getCreatedBy().getId();
                this.createdByName = htElectricitySettlementBillItemModel.getCreatedBy().getName();
            }
            if (htElectricitySettlementBillItemModel.getUpdatedBy() != null) {
                this.updatedById = htElectricitySettlementBillItemModel.getUpdatedBy().getId();
                this.updatedByName = htElectricitySettlementBillItemModel.getUpdatedBy().getName();
            }
        }

        public static List<HtElectricitySettlementBillItemModel.HtElectricitySettlementBillItemModelView> getViewListFromList(List<HtElectricitySettlementBillItemModel> htElectricitySettlementBillItemModelList) {
            return htElectricitySettlementBillItemModelList.stream().map(HtElectricitySettlementBillItemModel.HtElectricitySettlementBillItemModelView::new).toList();
        }
    }

    @Data
    @Schema(title = "电量结算单细项模板查询表单", description = "电量结算单细项模板查询参数")
    public static class HtElectricitySettlementBillItemModelFindDto {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "表模板id")
        private String billModelId;
        @Schema(description = "分页信息")
        private PageDto pageDto;

        public HtElectricitySettlementBillItemModel toHtElectricitySettlementBillItemModel() {
            return new HtElectricitySettlementBillItemModel(this);
        }
    }

    @Data
    @Schema(title = "电量结算单细项模板保存表单", description = "电量结算单细项模板保存参数")
    public static class HtElectricitySettlementBillItemModelSaveDto {
        @Schema(description = "id(如为空则为新增数据)")
        private String id;
        @Schema(description = "表模板id")
        private String billModelId;
        @Schema(description = "表模板名称")
        private String billModelName;
        @Schema(description = "接用类型")
        private String connectionType;
        @Schema(description = "接用地点")
        private String connectionLocation;
        @Schema(description = "计算规则")
        private String computationRule;
        @Schema(description = "排序参数")
        private Integer sortOrder;

        public HtElectricitySettlementBillItemModel toHtElectricitySettlementBillItemModel() {
            return new HtElectricitySettlementBillItemModel(this);
        }
    }
}
